import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:ls_work/config/global_configs.dart';
import 'package:ls_work/login/page/user_manager.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:base_flutter/base_flutter.dart';
import 'package:saas_order_meal/saas_order_meal.dart';

class PostRequest {
  static var urlencodedHeader =
      Options(contentType: Headers.formUrlEncodedContentType);

  ///获取活动记录
  static Future<Map> activityRecord(String customerNameLike,
      String activityNameLike, String joinTimeStart, String joinTimeEnd) async {
    var map = {
      "customerNameLike": customerNameLike,
      "activityNameLike": activityNameLike,
      "joinTimeStart": joinTimeStart,
      "joinTimeEnd": joinTimeEnd,
    };

    var result = await HttpUtil.instance.postData(HttpApi.activityRecordList,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///新增活动信息
  ///[topicActivityName] 活动名称
  ///[customerId] 长者id
  ///[joinTime] 参与时间
  static Future<Map> signActivity(
      String topicActivityName, String customerId, String joinTime) async {
    var map = {
      "topicActivityName": topicActivityName,
      "customerId": customerId,
      "joinTime": joinTime,
    };

    var result = await HttpUtil.instance.postData(HttpApi.signActivity,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///请假列表接口
  /// [customerNameLike] 姓名
  /// [validSign] 状态，1-已离院，0-已回院
  /// [leaveTimeStart] 离院时间-开始
  /// [leaveTimeEnd] 离院时间-结束
  /// [backTimeStart] 回院时间-开始
  /// [backTimeEnd] 回院时间-结束
  /// [accompanyNameLike] 陪同人
  /// [accompanyMobile] 陪同人电话
  static Future<Map> leaveRecordList(
      String customerNameLike,
      String validSign,
      String leaveTimeStart,
      String leaveTimeEnd,
      String backTimeStart,
      String backTimeEnd,
      String accompanyNameLike,
      String accompanyMobile) async {
    var map = {
      "customerNameLike": customerNameLike,
      "validSign": validSign,
      "leaveTimeStart": leaveTimeStart,
      "leaveTimeEnd": leaveTimeEnd,
      "backTimeStart": backTimeStart,
      "backTimeEnd": backTimeEnd,
      "accompanyNameLike": accompanyNameLike,
      "accompanyMobile": accompanyMobile,
    };
    var result = await HttpUtil.instance.postData(HttpApi.leaveRecordList,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///新增请假
  static Future<Map> addLeave({
    required String customerElderId,
    required String leaveTime,
    required String leaveReasonId,
    String? planBackTime,
    required String accompanyType,
    String? accompanyId,
    String? accompanyName,
    String? accompanyMobile,
    String? relationshipId,
    String? leaveRemark,
    String? backTime,
    String? sync,
  }) async {
    var map = {
      "customerElderId": customerElderId,
      "leaveTime": leaveTime,
      "leaveReasonId": leaveReasonId,
      "planBackTime": planBackTime,
      "accompanyType": accompanyType,
      "accompanyId": accompanyId ?? "",
      "accompanyName": accompanyName,
      "accompanyMobile": accompanyMobile ?? "",
      "relationshipId": relationshipId,
      "leaveRemark": leaveRemark,
      "backTime": backTime,
      "sync": sync,
    };
    var result = await HttpUtil.instance.postData(HttpApi.addLeave,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///获取字典值
  static Future<Map> getComboData(String codeTypeId) async {
    var map = {"codeTypeId": codeTypeId};
    var result = await HttpUtil.instance
        .postData(HttpApi.comboData, data: map, options: urlencodedHeader);
    return result;
  }

  ///点餐记录
  static Future<Map> getMealRecord(
      String elderNameLike, String createdDate) async {
    var map = {
      "elderNameLike": elderNameLike,
      "createdDate": createdDate,
      "wrapper": true,
    };
    var result = await HttpUtil.instance
        .postData(HttpApi.mealRecord, data: map, options: urlencodedHeader);
    return result;
  }

  ///菜单列表
  static Future<Map> getFoodMenu(
      {String? nameLike, String? flag, String? avoid}) async {
    var map = {
      "nameLike": nameLike ?? "",
      "avoid": avoid ?? "",
      "flag": flag ?? "1",
      "wrapper": true,
    };
    var result = await HttpUtil.instance
        .postData(HttpApi.foodMenuList, data: map, options: urlencodedHeader);
    return result;
  }

  ///提交点餐
  static Future<Map> submitFood(String customerId, String edibleDate,
      String timeRange, List<Map<String, dynamic>> details) async {
    var map = {
      "customerId": customerId,
      "edibleDate": edibleDate,
      "timeRange": timeRange,
      "details": details,
    };
    var result = await HttpUtil.instance.postData(HttpApi.submitMeal,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///就医记录
  static Future<Map> medicalRecord(dynamic branchId, String cityId) async {
    var map = {
      "branchId": branchId,
      "cityId": cityId,
    };
    map.removeWhere((key,value)=>value==null||value=='');
    var result = await HttpUtil.instance.postData(HttpApi.medicalRecord,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///添加就医信息
  static Future<Map> addMedical(
      String customerId,
      String medicalCauseType,
      String medicalReasons,
      String medicalTreatmentType,
      String medicalTimeType,
      String medicalPlan,
      String leaveTime,
      String backTime) async {
    var map = {
      "customerId": customerId,
      "medicalCauseType": medicalCauseType,
      "medicalReasons": medicalReasons,
      "medicalTreatmentType": medicalTreatmentType,
      "medicalTimeType": medicalTimeType,
      "medicalPlan": medicalPlan,
      "leaveTime": leaveTime,
      "backTime": backTime,
    };
    var result = await HttpUtil.instance.postData(HttpApi.addMedical,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///服务单统计
  static Future<Map> serviceOrderStatistics(String beginRequestTime) async {
    var map = {"beginRequestTime": beginRequestTime};
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.serviceOrderStatistics,
      data: map,
    );
    return result;
  }

  ///服务单列表
  static Future<Map> serviceOrderList(String statusId, int page, int row,
      {int pcOrApp = 2}) async {
    var map = {
      "statusId": statusId,
      "page": page,
      "row": row,
      "pcOrApp": pcOrApp,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.serviceOrderList,
      data: map,
    );
    return result;
  }

  ///服务单列表
  static Future<Map> serviceOrderListNoFilter(
      String statusId, int page, int row,
      {dynamic type,
      String? markStartDate,
      String? markEndDate,
      dynamic serveTypeId,
      dynamic serveItemId}) async {
    var map = {
      "statusId": statusId,
      "page": page,
      "row": row,
      "type": type,
      "markStartDate": markStartDate,
      "markEndDate": markEndDate,
      "serveTypeId": serveTypeId,
      "serveItemId": serveItemId,
    };
    map.removeWhere((key,value)=>value==null||value=="");
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.serviceOrderListNoFilter,
      data: map,
    );
    return result;
  }

  ///我的服务单列表
  static Future<Map> myServiceOrderList(
      String statusId, int page, int row) async {
    var map = {
      "statusId": statusId,
      "page": page,
      "row": row,
      "pcOrApp": 2,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.myServiceOrderList,
      data: map,
    );
    return result;
  }

  ///服务单详情
  static Future<Map> serviceOrderDetail(String orderId) async {
    var map = {
      "id": orderId,
    };
    var result = await HttpUtil.instance.postData(
        ServiceOrderApis.serviceOrderDetail,
        data: map,
        options: urlencodedHeader);
    return result;
  }

  ///服务单接单
  static Future<Map> receiveOrder(String orderId) async {
    var map = {"id": orderId};
    var result = await HttpUtil.instance.postData(ServiceOrderApis.receiveOrder,
        data: map, options: urlencodedHeader);
    return result;
  }

  ///待接单-拒单
  static Future<Map> refuseOrder(String orderId, String reason) async {
    var map = {"id": orderId, "reason": reason};
    var result = await HttpUtil.instance
        .postData(ServiceOrderApis.refuseOrder, data: map);
    return result;
  }

  ///上传文件
  static Future<Map> uploadFile(
    String filePath,
  ) async {
    var fileType = filePath.split(".").last;
    var map = {
      "file": await MultipartFile.fromFile(filePath),
      'fileType': fileType,
    };
    var result = await HttpUtil.instance
        .postData(HttpApi.uploadFile, data: FormData.fromMap(map));
    return result;
  }

  ///开始服务
  static Future<Map> startService(
      String id, String startTime, List<dynamic> attachList,
      {String? site,
      String? serveAddress,
      double? longitude,
      double? latitude}) async {
    var map = {
      "id": id,
      "startTime": startTime,
      "attachList": attachList,
      "site": site,
      "serveAddress": serveAddress,
      "longitude": longitude,
      "latitude": latitude,
    };
    map.removeWhere((key, value) => value == null || value == "");
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.startService,
      data: map,
    );
    return result;
  }

  ///完成服务
  static Future<Map> finishService(
    String id,
    String finishTime,
    String accomplishRemark,
    String acturalPrice,
    String payId,
    List<dynamic> attachList,
    String commonExecutorName,
    String commonExecutorId,
    int? payStatus, {
    String? site,
    String? serveAddress,
    double? longitude,
    double? latitude,
  }) async {
    var map = {
      "id": id,
      "finishTime": finishTime,
      "accomplishRemark": accomplishRemark,
      "acturalPrice": acturalPrice,
      "payId": payId,
      "attachList": attachList,
      "commonExecutorName": commonExecutorName,
      "commonExecutorId": commonExecutorId,
      "payStatus": payStatus,
      "site": site,
      "serveAddress": serveAddress,
      "longitude": longitude,
      "latitude": latitude,
    };
    map.removeWhere((key, value) => value == null || value == "");
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.finishService,
      data: map,
    );
    return result;
  }

  ///继续服务
  static Future<Map> nextService(String id, String accomplishRemark,
      String nextTime, List<dynamic> attachList) async {
    var map = {
      "id": id,
      "accomplishRemark": accomplishRemark,
      "nextTime": nextTime,
      "attachList": attachList,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.nextService,
      data: map,
    );
    return result;
  }

  ///服务完成-拒单
  static Future<Map> refuseStartedOrder(String id, String requestTurnTime,
      String turnRemark, List<dynamic> attachList) async {
    var map = {
      "id": id,
      "requestTurnTime": requestTurnTime,
      "turnRemark": turnRemark,
      "attachList": attachList,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.refuseStartedOrder,
      data: map,
    );
    return result;
  }

  ///服务项目列表
  static Future<Map> serviceItemList(int page, int pageLength) async {
    var map = {
      "page": page,
      "row": pageLength,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.serviceItemList,
      data: map,
    );
    return result;
  }

  ///服务项目内容
  static Future<Map> serviceItemContent(String typeId, int page, int row,
      {String itemName = ""}) async {
    var map = {
      "typeId": typeId,
      "page": page,
      "row": row,
      "itemName": itemName,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.serviceItemContent,
      data: map,
    );
    return result;
  }

  ///年统计
  static Future<Map> serviceYearStatistics(String year) async {
    var map = {
      "yearTime": year,
    };
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.yearStatistics,
      data: map,
    );
    return result;
  }

  ///部门列表
  static Future<Map> departmentList() async {
    var map = {};
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.departmentList,
      data: map,
    );
    return result;
  }

  ///新增工单
  ///[serveId] 服务类型
  ///[serveTypeId] 服务项目
  ///[serveItemId] 服务内容
  ///[remark] 备注
  ///[officeId] 部门id
  ///[markTime] 预约时间
  ///[requestType] 长者10259 员工10260
  ///[familyAddressId] 居家服务地点id
  ///[familyHumanId] 居家服务长者id
  ///[commonAddress] 公区/居家报修服务地点
  ///[commonHuman] 公区服务对象
  static Future<Map> createServiceOrder(
      {required String serveId,
      required String serveTypeId,
      required String serveItemId,
      required String remark,
      String? officeId,
      required String markTime,
      required String requestType,
      String familyAddressId = "",
      String familyHumanId = "",
      required String commonAddress,
      required String commonHuman,
      String? buildingId,
      String? floorId,
      List<dynamic> attachList = const []}) async {
    var map = <String, dynamic>{
      "serveId": serveId,
      "serveTypeId": serveTypeId,
      "serveItemId": serveItemId,
      "remark": remark,
      "officeId": officeId,
      "markTime": markTime,
      "requestType": requestType,
      "commonAddress": commonAddress,
      "commonHuman": commonHuman,
      "buildingId": buildingId,
      "floorId": floorId,
    };
    if (familyHumanId.isNotEmpty) {
      map["familyAddressId"] = familyAddressId;
      map['familyHumanId'] = familyHumanId;
    }

    if (attachList.isNotEmpty) {
      map['attachList'] = attachList;
    }
    var result = await HttpUtil.instance.postData(
      ServiceOrderApis.createServiceOrder,
      data: map,
    );
    return result;
  }

  ///服务过程
  static Future<Map> serviceOrderProcess(String id) async {
    var map = {"id": id};
    var result = await HttpUtil.instance.postData(
        ServiceOrderApis.serviceOrderProcess,
        data: map,
        options: urlencodedHeader);
    return result;
  }

  ///登录人信息
  static Future<Map> userInfo() async {
    var map = {"row": 0};
    var result =
        await HttpUtil.instance.postData(ServiceOrderApis.userInfo, data: map);
    return result;
  }

  ///评价配置信息
  static Future<Map> ratingConfig() async {
    var map = {"row": 0};
    var result = await HttpUtil.instance
        .postData(ServiceOrderApis.ratingConfig, data: map);
    return result;
  }

  ///提交评价
  static Future<Map> submitRating(
      String star, String content, String id, List configList) async {
    var map = {
      "star": star,
      "content": content,
      "id": id,
      "configList": configList,
    };
    var result = await HttpUtil.instance
        .postData(ServiceOrderApis.submitRating, data: map);
    return result;
  }

  ///获取老人服务计划统计信息
  static Future<Map> oldServiceStatistics(
      dynamic elderCode, String planFinishDate, dynamic customerElderId) async {
    var map = {
      "planFinishDate": planFinishDate,
    };

    if (elderCode != null) {
      map["elderCode"] = elderCode;
    }
    if (customerElderId != null) {
      map["customerElderId"] = customerElderId;
    }
    var result = await HttpUtil.instance.postData(
        ServiceExecuteApi.oldServiceStatistics,
        data: map.toJsonMapStr(),
        options: urlencodedHeader);
    return result;
  }

  ///客户服务列表
  static Future<Map> oldServicePlanList(dynamic elderCode,
      dynamic customerElderId, dynamic planFinishDate, String? status,
      {int page = 1, int rows = 20}) async {
    var map = {
      "planFinishDate": planFinishDate,
      "status": status,
    };
    if (elderCode != null) {
      map["elderCode"] = elderCode;
    }
    if (customerElderId != null) {
      map["customerElderId"] = customerElderId;
    }

    var requestMap = {"jsonStr": jsonEncode(map), "page": page, "rows": rows};
    var result = await HttpUtil.instance.postData(
        ServiceExecuteApi.oldServiceList,
        data: requestMap,
        options: urlencodedHeader);
    return result;
  }

  ///客户服务列表
  static Future<Map> newOldServicePlanList(String? elderCode,
      dynamic customerElderId, String planFinishDate, String status) async {
    var map = {
      "planFinishDate": planFinishDate,
      "status": status,
    };
    if (elderCode != null) {
      map["elderCode"] = elderCode;
    }
    if (customerElderId != null) {
      map["customerElderId"] = customerElderId;
    }
    var result = await HttpUtil.instance.postData(
        ServiceExecuteApi.newOldServiceList,
        data: map.toJsonMapStr(),
        options: urlencodedHeader);
    return result;
  }

  ///获取巡防任务
  static Future<Map> patrolList(String patrolRange) async {
    var map = <String, String>{};
    if (!patrolRange.isNullOrEmpty()) {
      map["patrolRange"] = patrolRange;
    }
    var result =
        await HttpUtil.instance.getData(PatrolApi.patrolList, data: map);
    return result;
  }

  ///二维码扫描获取详情
  static Future<Map> scanGetPatrolDetail(String content,
      {String? executeTaskId}) async {
    var map = <String, dynamic>{
      "content": content,
    };
    if (!executeTaskId.isNullOrEmpty()) {
      map["executeTaskId"] = executeTaskId;
    }
    var result = await HttpUtil.instance
        .postData(PatrolApi.scanCode, data: map, options: urlencodedHeader);
    return result;
  }

  ///巡防点提交
  static Future<Map> submitPatrol(
      dynamic id, String resultStatus, String feedback,
      {dynamic isSupplementaryCard}) async {
    var map = {
      "id": id,
      "resultStatus": resultStatus,
      "feedback": feedback,
    };
    if (isSupplementaryCard != null) {
      map["isSupplementaryCard"] = isSupplementaryCard;
    }
    var result = await HttpUtil.instance
        .postData(PatrolApi.submitPatrol, data: map, options: urlencodedHeader);
    return result;
  }

  static Future<Map> uploadAbnormal(
    dynamic id,
    String resultStatus,
    String feedback,
  ) async {
    var map = {
      "id": id,
      "resultStatus": resultStatus,
      "feedback": feedback,
      "abnormalRegistrationTime": DateTime.now()
          .toDateStr([yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss])
    };

    var result = await HttpUtil.instance.postData(PatrolApi.uploadAbnormal,
        data: map.toRequestStr(), options: urlencodedHeader);
    return result;
  }

  ///楼栋列表
  static Future<Map> buildingList() async {
    var result = await HttpUtil.instance.postData(DevicesApis.buildingList);
    return result;
  }

  ///设备列表
  static Future<Map> equipmentList(int page, int row, String buildingId) async {
    var map = {"page": page, "row": row, "buildingId": buildingId};
    var result = await HttpUtil.instance.postData(DevicesApis.equipmentList,
        data: map, options: urlencodedHeader);
    return result;
  }

  ///设备任务列表
  static Future<Map> getEquipmentTask(
      dynamic content, dynamic equipmentId) async {
    var map = {"content": content, "equipmentId": equipmentId};
    var result = await HttpUtil.instance.postData(
        DevicesApis.scanGetEquipmentList,
        data: map,
        options: urlencodedHeader);
    return result;
  }

  ///提交维保
  static Future<Map> submitEquipmentTask(String id, String content,
      String executeDate, String resultStatus) async {
    var map = {
      "id": id,
      "content": content,
      "executeDate": executeDate,
      "resultStatus": resultStatus,
    };

    var result = await HttpUtil.instance.postData(DevicesApis.submitRepair,
        data: map, options: urlencodedHeader);
    return result;
  }

  ///维保记录
  static Future<Map> equipmentRepairRecord(
      dynamic id, dynamic content, int row, int page) async {
    var map = {
      "equipmentId": id,
      "content": content,
      "row": row,
      "page": page,
    };
    var result = await HttpUtil.instance.postData(DevicesApis.repairRecord,
        data: map, options: urlencodedHeader);
    return result;
  }

  ///点餐模式列表
  static Future<Map> getOrderModel(int page, int rows,
      {int isDel = 0, int status = 0}) async {
    var map = {
      "page": page,
      "rows": rows,
      "isDel": isDel,
      "status": status,
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.orderModel,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///场所列表
  static Future<Map> getSiteList(String orderType) async {
    var map = {"orderModelId": orderType};
    var result = await HttpUtil.instance
        .postData(BookFoodApis.siteList, data: map, options: urlencodedHeader);
    return result;
  }

  ///菜品列表
  static Future<Map> foodMenuList(String siteId, String supplyDate,
      String mealSection, String orderModelType) async {
    var map = {
      "siteId": siteId,
      "supplyDate": supplyDate,
      "mealSection": mealSection,
      "orderModelType": orderModelType,
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.goodList,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///菜品列表
  static Future<Map> singleFoodMenu(String siteId) async {
    var map = {
      "siteId": siteId,
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.singleMenu,
        data: map, options: urlencodedHeader);
    if ("0" == result['code']) {
      return result;
    } else {
      throw result['msg'];
    }
  }

  ///扫码获取老人
  static Future<Map> scanOld(String elderHumanId) async {
    var map = {"elderHumanId": elderHumanId};
    var result = await HttpUtil.instance.postData(BookFoodApis.scanOld,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///周菜单
  static Future<Map> weekMenu(String? time, String? siteId,
      String? elderHumanId, String? orderModelType) async {
    var map = {
      "time": time,
      "siteId": siteId,
      "elderHumanId": elderHumanId,
      "orderModelType": orderModelType
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.weekMenu,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  static Future<Map> submitOrder(
      {String? siteId,
      String? elderHumanId,
      String? orderDate,
      String? useDate,
      String? useTimeSection,
      String? useAddr,
      String? useType,
      String? useNum,
      String? orderModelType,
      String? isWeek,
      String? payment,
      String? packFee,
      List<Map>? goodsList,
      String? remark}) async {
    var map = {
      "siteId": siteId ?? "",
      "elderHumanId": elderHumanId ?? "",
      "orderDate": orderDate ?? "",
      "useDate": useDate ?? "",
      "useTimeSection": useTimeSection ?? "",
      "useAddr": useAddr,
      "useType": useType ?? "",
      "useNum": useNum ?? "",
      "orderModelType": orderModelType ?? "",
      "isWeek": isWeek ?? "",
      "payment": payment,
      "packFee": packFee,
      "remark": remark,
      "goodsList": goodsList ?? [],
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.submitOrder,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  static Future<Map> oneCardSubmit(
      {String? siteId,
      String? elderHumanId,
      String? orderDate,
      String? useDate,
      String? useTimeSection,
      String? useAddr,
      String? useType,
      String? useNum,
      String? orderModelType,
      String? isWeek,
      String? payment,
      String? packFee,
      List<Map>? goodsList,
      String? remark}) async {
    var map = {
      "siteId": siteId ?? "",
      "elderHumanId": elderHumanId ?? "",
      "orderDate": orderDate ?? "",
      "useDate": useDate ?? "",
      "useTimeSection": useTimeSection ?? "",
      "useAddr": useAddr,
      "useType": useType ?? "",
      "useNum": useNum ?? "",
      "orderModelType": orderModelType ?? "",
      "isWeek": isWeek ?? "",
      "payment": payment,
      "packFee": packFee,
      "remark": remark,
      "goodsList": goodsList ?? [],
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.oneCardSubmit,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///支付订单
  static Future<Map> payOrder(
      {String? orderId,
      String payment = "1",
      String? type,
      String? totalMoney}) async {
    var map = {"id": orderId, "type": type};
    if (!payment.isNullOrEmpty()) {
      map['payment'] = payment;
    }
    if (!totalMoney.isNullOrEmpty()) {
      map['totalMoney'] = totalMoney;
    }
    var result = await HttpUtil.instance.postData(BookFoodApis.payOrder,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  static Future<Map> oneCardPay(
      {String? orderId,
      String? payment = "1",
      String? type,
      String? totalMoney}) async {
    var map = {"id": orderId, "type": type};
    if (!payment.isNullOrEmpty()) {
      map['payment'] = payment;
    }
    if (!totalMoney.isNullOrEmpty()) {
      map['totalMoney'] = totalMoney;
    }
    var result = await HttpUtil.instance.postData(BookFoodApis.oneCardPay,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///支付订单
  static Future<Map> weekPayOrder(
      {String? orderId,
      String? payment = "1",
      String? type,
      String? totalMoney}) async {
    var map = {"id": orderId, "type": type};
    if (!payment.isNullOrEmpty()) {
      map['payment'] = payment;
    }
    if (!totalMoney.isNullOrEmpty()) {
      map['totalMoney'] = totalMoney;
    }
    var result = await HttpUtil.instance.postData(BookFoodApis.weekPayOrder,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///解析二维码
  static Future<Map> decodeQrcode(String code) async {
    var map = {'code': code};
    var result = await HttpUtil.instance
        .postData(HttpApi.decodeQrcode, data: map, options: urlencodedHeader);
    return result;
  }

  ///床位基本信息
  static Future<Map> bedInfo(String bedId) async {
    var map = {"bedId": bedId};
    var result = await HttpUtil.instance
        .postData(HttpApi.bedInfo, data: map, options: urlencodedHeader);
    return result;
  }

  ///床位入住记录
  static Future<Map> bedRecord(String bedId, int page, int rows) async {
    var map = {"bedId": bedId, "page": page, "rows": rows};
    var result = await HttpUtil.instance.postData(
      HttpApi.bedRecord,
      data: map,
    );
    return result;
  }

  ///点餐记录
  static Future<Map> orderRecordList(
      {int page = 1,
      int rows = 20,
      String elderHumanName = "",
      String? buildingId,
      String? floorId,
      String? startCreateTime,
      String? endCreateTime,
      String? useTimeSection,
      String? useDate,
      String? useType,
      String? orderCodeLike,
      String? cardType}) async {
    var map = {
      "page": page,
      "rows": rows,
      "elderHumanName": elderHumanName,
      "buildingId": buildingId,
      "floorId": floorId,
      "startCreateTime": startCreateTime,
      "endCreateTime": endCreateTime,
      "useTimeSection": useTimeSection,
      "useDate": useDate,
      "useType": useType,
      "orderCodeLike": orderCodeLike,
      "cardType": cardType
    };
    if (GlobalConfigs.useArea) {
      map['createdBy'] = UserManager.humanId;
      // map['isWeek'] = 1;
    }
    map.removeWhere((key, value) => value == null);
    var result = await HttpUtil.instance
        .postData(BookFoodApis.orderList, data: map, options: urlencodedHeader);
    return result;
  }

  ///周下单
  static Future<Map> submitWeekOrder(
      String? menuId,
      String? weekMenuModel,
      String? siteId,
      String? elderHumanId,
      String? time,
      String? orderModelType,
      String? remark,
      List<Map<String, dynamic>> content,
      String? tenantId,
      String? saasId,
      String? useType) async {
    var map = {
      "siteId": siteId,
      "elderHumanId": elderHumanId,
      "time": time,
      "orderModelType": orderModelType,
      "remark": remark,
      "content": content,
      "menuId": menuId,
      "weekMenuModel": weekMenuModel,
      "useType": useType,
      // "tenantId": tenantId,
      // "saasId": saasId,
    };
    var result = await HttpUtil.instance.postData(BookFoodApis.submitWeekOrder,
        data: map.toJsonMapStr(), options: urlencodedHeader);
    return result;
  }

  ///服务执行统计列表
  static Future<Map> serviceExecuteStatistics(
      {String? status,
      String? planFinishDateFin1,
      String? planFinishDateFin2,
      String? fuzzyQuery,
      String? buildingId,
      String? floorId,
      String? customerIdStr,
      int page = 1,
      int rows = 20}) async {
    var map = {
      "status": status,
      "planFinishDateFin1": planFinishDateFin1,
      "planFinishDateFin2": planFinishDateFin2,
      "fuzzyQuery": fuzzyQuery,
      "page": page,
      "rows": rows,
      "buildingId": buildingId,
      "floorId": floorId,
      "customerIdStr": customerIdStr,
    };
    map.removeWhere((key, value) => value == null);
    var result = await HttpUtil.instance.postData(
        ServiceExecuteApi.serviceExecuteStatistics,
        data: map,
        options: urlencodedHeader);
    return result;
  }

  static Future<String> getUUid(String branchId) async {
    var map = {
      "branchId": branchId,
    };
    var data = await HttpGo.instance.getDataString(HttpApi.getUuid, data: map);
    return data.toString();
  }
}

extension MapExt on Map {
  Map<String, dynamic> toJsonMapStr({String format = "jsonStr"}) {
    return {"$format": json.encode(this)};
  }
}
